home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / sgi.lha / Geomview / data / shaders / hlight.sl next >
Text File  |  1993-11-15  |  1KB  |  53 lines

  1. /* hlight.sl:    shader for point lights in hyperbolic space
  2.  * Author:    Charlie Gunn
  3.  * Description: 
  4.  *    See hplastic.sl also. 
  5.  *    This simulates a point light in hyperbolic space.  The brightness of the light
  6.  *    decays exponentially since the surface area of the sphere of radius r in hyperbolic
  7.  *    space is exp(kr) for some constant k.    Distance is given by Arccosh({p1,p1}),
  8.  *    where {p1,p0} is the Minkowski inner product on projective space.
  9.  */
  10.  
  11.  
  12. light
  13. hlight(
  14.     float k1 = 0.5,
  15.     intensity = 1;
  16.     color lightcolor = color (1, 1, .1);
  17.         point from = point "camera" (0,0,0);    /* light position */
  18.     )
  19. {
  20.     float    inpro, hdis, d;        /* hyperbolic distance (sort of) */
  21.     float  PP, QQ, PQ, tmp, PdotP;
  22.     point sP;
  23.  
  24.     Cl = 0;
  25.     illuminate(from)    {
  26.         sP = from + L;        /* need to reconstruct the position of light */
  27.         PdotP = sP.sP;
  28.         if (PdotP >= 1.0)    {
  29.             d = 1.0/sqrt(PdotP);
  30.             setxcomp(sP, d * xcomp(sP));
  31.             setycomp(sP, d * ycomp(sP));
  32.             setzcomp(sP, d * zcomp(sP));
  33.             PdotP = sP.sP;    
  34.             }
  35.         PP =  1.0 - PdotP;
  36.         if (PP < 0 ) PP = 0;
  37.         QQ =  1.0 - from.from;
  38.         /* if (QQ < 0 ) QQ = 0; if the light's bad, we're doomed */
  39.         PQ =  1.0 - sP.from;
  40.         /* if (PQ < 0 ) PQ = 0; ditto */
  41.         
  42.         d = PP * QQ;
  43.         if (d > 0) {
  44.             inpro = PQ / sqrt (d);
  45.             hdis = log(inpro + sqrt((abs(inpro*inpro - 1))));
  46.             Cl += intensity * lightcolor * (exp(-k1*hdis));
  47.             }    
  48.         else Cl = 0;
  49.         }
  50. }
  51.  
  52.  
  53.